package lab03.test04;

import java.io.*;

/**
 * Created by V555 on 2017/12/19.
 */
public class Test {
    public static void main(String[] args) {
        FileInputStream fileInputStream=null;
        FileOutputStream fileOutputStream=null;
        String s="";
        File file1=new File("D;\\source");
        file1.mkdir();
        File file2=new File("D:\\target");
        file2.mkdir();
        try {
            fileOutputStream=new FileOutputStream("D:\\source\\High.mp3");
            fileOutputStream.write(new String("sdfsdfsdf").getBytes());
            System.out.println("已写入");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fileInputStream=new FileInputStream("D:\\source\\High.mp3");
            byte[] b=new byte[fileInputStream.available()];
            while (fileInputStream.read(b)!=-1){
                s=new String(b);
            }
            System.out.println("读取成功");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            fileOutputStream=new FileOutputStream("D:\\target\\High.mp3");
            fileOutputStream.write(new String(s).getBytes());
            System.out.println("写入成功");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
